﻿using _2._4增删改查.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _2._4增删改查.Controllers
{
    public class DefaultController : Controller
    {
        // GET: Default
        /// <summary>
        /// 显示person表的列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            //从数据库中取值
            var context = new SchoolEntities();//实例化
            var result = context.People.ToList();//取出所有的person

            return View(result);
        }

        /// <summary>
        /// 显示person的详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Detail(int id)
        {
            //从数据中，根据id取出指定的人
            var context = new SchoolEntities();
            var person = context.People.Find(id);
            return View(person);
        }

        public ActionResult Delect(int id)
        {
            var context = new SchoolEntities();
            //找到指定id的人
            var person = context.People.Find(id);
            //调用remove方法删除找到的人
            context.People.Remove(person);
            context.SaveChanges();
            //跳转回主页
            return RedirectToAction("Index");
        }
    }
}